import Vue from 'vue'
import Router from 'vue-router'
import Data from '../components/oil/OilData.vue'
import Shouru from '../components/shouru/Shouru.vue'
import Home from '../components/Home.vue'
import Urea1 from '../components/urea/Urea1.vue'
import Welcome from '../components/Welcome.vue'
import Cards from '../components/cards/Cards.vue'
import AddData from '../components/data/AddData.vue'
import Login from '../components/Login.vue'
import CustomList from '../components/custom/CustomList.vue'
import Users from '../components/users/Users.vue'
import Panel from '../components/imobile/Panel'
import Member from '../components/users/Member.vue'
import ShouruManage from '../components/users/ShouruManage.vue'
import XiaoShou from '../components/users/XiaoShou.vue'
import Shuju from '../components/users/Shuju.vue'
// import App from './App.vue'
Vue.use(Router)
Vue.use(Data)
Vue.use(Shouru)
Vue.use(Home)
Vue.use(Urea1)
Vue.use(Welcome)
Vue.use(Cards)
Vue.use(AddData)
Vue.use(Login)
Vue.use(CustomList)
Vue.use(Users)
Vue.use(Panel)
Vue.use(Member)
Vue.use(ShouruManage)
Vue.use(XiaoShou)
Vue.use(Shuju)

const router = new Router({
    // mode: 'history',
    routes: [{
            path: '/',
            redirect: '/login'
        }, {
            path: '/login',
            component: Login
        },
        {
            path: '/home',
            component: Home,
            redirect: '/welcome',
            children: [{
                path: '/welcome',
                component: Welcome
            }, {
                path: '/oil',
                component: Data
            }, {
                path: '/shouru',
                component: Shouru

            }, {
                path: '/urea1',
                component: Urea1
            }, {
                path: '/cards',
                component: Cards
            }, {
                path: '/addData',
                component: AddData
            }, {
                path: '/panel',
                component: Panel
            }, {
                path: '/customlist',
                component: CustomList
            }, {
                path: '/users',
                component: Users
            }, {
                path: '/member',
                component: Member
            }, {
                path: '/shouruManage',
                component: ShouruManage
            }, {
                path: '/xiaoshou',
                component: XiaoShou
            }, {
                path: '/shuju',
                component: Shuju
            }]
        }
    ]
})
router.beforeEach((to, form, next) => {
    if (to.path === '/login') return next()
    const tokenr = sessionStorage.getItem('token')
    if (!tokenr) return next('/login')
    next()
})
export default router